package main.builderpattern;

/**
 * Created by lantianixang1 on 2018/9/22.
 **/
public class Result {
    private Integer code;
    private String msg;
    private Boolean success;

    public static ResultBuilder builder(){
        ResultBuilder builder = new ResultBuilder();
        return builder;
    }

    public Result(ResultBuilder builder) {
        setCode(builder.code);
        setMsg(builder.msg);
        setSuccess(builder.success);
    }

    public static class ResultBuilder{
        private Integer code;
        private String msg;
        private Boolean success;

        public ResultBuilder code(Integer code){
            this.code = code;
            return this;
        }

        public ResultBuilder msg(String msg){
            this.msg = msg;
            return this;
        }

        public ResultBuilder success(Boolean success){
            this.success = success;
            return this;
        }

        public Result build(){
            return new Result(this);
        }
    }

    public Integer getCode() {
        return code;
    }

    private void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }

    public Boolean getSuccess() {
        return success;
    }

    private void setSuccess(Boolean success) {
        this.success = success;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", success=" + success +
                '}';
    }
}
